package com.egao.orderB.controller;

import com.egao.common.core.annotation.ApiPageParam;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.DriverOilMainCard;
import com.egao.orderB.service.DriverOilMainCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;


/**
 *
 * 油卡
 * @author : Doman
 * @date : 2021-07-07 17:00:42
 * @version ：1.0
 */

@Api(tags = "油卡主卡设置")
@RestController
@RequestMapping("/api/orderB/driverOilMainCard")
public class DriverOilMainCardController extends BaseController {

	@Autowired
	private DriverOilMainCardService driverOilMainCardService;

	/**
	 * 分页查询列表
	 */
	@PreAuthorize("hasAuthority('orderB:driverOil:list')")
    //@OperLog(value = "油卡", desc = "分页查询")
    @ApiOperation(value ="分页查询油卡",notes = "" +
        "limit:每页显示几行 必填\n" +
        "page:第几页 必填\n" +
        "cardNo;//卡号\n" +
        " \n\n\n" +
        "返回的结果:\n" +
        "id:id\n" +
        "companyName:公司名称\n" +
        "cardNo:卡号\n" +
        "price:金额\n" +
        "oilPrice:油价\n" +
        "oil:油量(升)\n" +
        "remark:备注\n" +
        "createTime:创建时间\n" +
        "createUser:创建人\n" +
        "updateTime:更新时间\n" +
        "updateUser:更新人\n" +
        "",httpMethod = "POST")
    @ApiPageParam
    @PostMapping("/list")
    public JsonResult page(PageResult2<T> page, DriverOilMainCard driverOilMainCard) throws Exception{
        return driverOilMainCardService.list(page, driverOilMainCard, getLoginUser());
    }

    /**
     * 查询全部油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:list')")
    //@OperLog(value = "油卡", desc = "查询全部")
    @ApiOperation("查询全部油卡")
    @PostMapping("/listAll")
    public JsonResult list(DriverOilMainCard driverOilMainCard){
        return driverOilMainCardService.list(driverOilMainCard, getLoginUser());
    }

    /**
     * 根据id查询油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:list')")
    //@OperLog(value = "油卡", desc = "根据id查询")
    @ApiOperation("根据id查询油卡")
    @PostMapping("/get")
    public JsonResult get(DriverOilMainCard driverOilMainCard) {
        return driverOilMainCardService.getById(driverOilMainCard);
		// 使用关联查询
        //PageParam<driverOilMainCard> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<driverOilMainCard> records = driverOilMainCardService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:save')")
    @OperLog(value = "油卡", desc = "添加", param = false, result = true)
    @ApiOperation(value ="添加油卡",notes = "" +
            "companyName:公司名称\n" +
            "cardNo:卡号\n" +
            "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/save")
    public JsonResult save(Model model, DriverOilMainCard driverOilMainCard) {
        return driverOilMainCardService.save(driverOilMainCard, getLoginUser());
    }


    /**
     * 充值油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:save')")
    @OperLog(value = "充值油卡", desc = "充值油卡", param = false, result = true)
    @ApiOperation(value ="充值油卡",notes = "" +
            "id:主卡id\n" +
            "price:金额\n" +
            "oilPrice:油价\n" +
            "oil:油量(升)\n" +
            "reDate  时间\n" +
        "",httpMethod = "POST")
    @PostMapping("/recharge")
    public JsonResult recharge(Model model, DriverOilMainCard driverOilMainCard) {
        return driverOilMainCardService.recharge(driverOilMainCard, getLoginUser());
    }

    /**
     * 修改油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:update')")
    @OperLog(value = "油卡", desc = "修改", param = false, result = true)
    @ApiOperation(value ="修改油卡",notes = "" +
            "id:id\n" +
            "companyName:公司名称\n" +
            "cardNo:卡号\n" +
            "price:金额\n" +
            "oilPrice:油价\n" +
            "oil:油量(升)\n" +
            "remark:备注\n" +
        "",httpMethod = "POST")
    @PostMapping("/update")
    public JsonResult update(Model model, DriverOilMainCard driverOilMainCard) {
        return driverOilMainCardService.update(driverOilMainCard, getLoginUser());
    }

    /**
     * 删除油卡
     */
    @PreAuthorize("hasAuthority('orderB:driverOil:remove')")
    @OperLog(value = "油卡", desc = "删除", result = true)
    @ApiOperation("删除油卡")
    @PostMapping("/remove")
    public JsonResult remove(DriverOilMainCard driverOilMainCard ) {
        return driverOilMainCardService.remove(driverOilMainCard, getLoginUser());
    }

    /**
     * 批量添加油卡
     */
    /**@RequiresPermissions("orderB:driverOil:save")
    @OperLog(value = "油卡", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @PostMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<DriverOilMainCard> list) {
        if (driverOilMainCardService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改油卡
     */
    /**@RequiresPermissions("orderB:driverOil:update")
    @OperLog(value = "油卡", desc = "批量修改", result = true)
    @ResponseBody
    @PostMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<DriverOilMainCard> batchParam) {
        if (batchParam.update(driverOilMainCardService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除油卡
     */
    /**@RequiresPermissions("orderB:driverOil:remove")
    @OperLog(value = "油卡", desc = "批量删除", result = true)
    @ResponseBody
    @PostMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (driverOilMainCardService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
